/**
 * 获取样式
 * @param el
 * @param name
 * @returns {CSSStyleDeclaration|*}
 */
export function getStyle (el, name) {
  if (window.getComputedStyle) {
    return window.getComputedStyle(el, null)
  } else {
    return el.currentStyle
  }
}

//获取线形图Option
export function getLineOption (nameArr, xNameArr, chartArr) {
  let option = {
    toolbox: {
      padding: 10,
      right: 50,
      show: true,
      feature: {
        mark: { show: true },
        magicType: { show: true, type: ['line', 'bar'] },
        restore: { show: true },
        saveAsImage: { show: true },
      }
    },
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      top: '10',
      right: '200',
      textStyle: {
        color: 'red'
      },
      data: nameArr,

    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      axisLabel: {
        textStyle: {
          color: '#00baff',//坐标值得具体的颜色
        }
      },
      data: xNameArr
    },
    yAxis: {
      type: 'value',
      nameTextStyle: {
        color: '#ebf8ac'
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: ['#315070'],
          width: 1,
          type: 'solid'
        }
      },
      axisLabel: {
        textStyle: {
          color: '#00baff',//坐标值得具体的颜色
        }
      }
    },
    series: []
  }

  chartArr.forEach(item => {
    item.type = 'line'
    var time = new Date()
    var hour = time.getHours()
    var minute = time.getMinutes()
    var mm = item.data
    for (var i = 0; i < xNameArr.length; i++) {
      if (xNameArr[i].substring(0, 2) > hour) {
        mm[i] = ''
      }
      if (parseInt(xNameArr[i].substring(0, 2)) === hour && 0 < minute && minute < parseInt(xNameArr[i].substr(3, 2))) {
        mm[i] = ''
      }
    }
    option.series.push(item)
  })
  return option
}

//获取柱状图Option
export function getBarOption (nameArr, xNameArr, chartArr) {
  let option = {

    tooltip: {
      trigger: 'axis'
    },
    legend: {
      top: '0',
      right: '200',
      textStyle: {
        color: '#00baff'
      },
      data: nameArr
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    toolbox: {
      padding: 20,
      right: 50,
      show: true,
      feature: {
        mark: { show: true },
        magicType: { show: true, type: ['line', 'bar'] },
        restore: { show: true },
        saveAsImage: { show: true }
      }
    },
    xAxis: {

      axisLabel: {
        textStyle: {
          color: '#00baff' // 坐标值得具体的颜色
        }
      },
      data: xNameArr
    },
    yAxis: {
      type: 'value',
      nameTextStyle: {
        color: '#ebf8ac'
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: ['#315070'],
          width: 1,
          type: 'solid'
        }
      },
      axisLabel: {
        textStyle: {
          color: '#06c7bb' // 坐标值得具体的颜色
        }
      }
    },
    series: []
  }

  chartArr.forEach(item => {
    item.type = 'bar'
    item.barWidth = 20
    option.series.push(item)
  })

  return option
}

// 获取饼状图option
export function getPieOption (nameArr, chartArr) {
  const option = {
    tooltip: {
      trigger: 'item',
      formatter: '{a} <br/>{b}: {c} ({d}%)'
    },
    toolbox: {
      padding: 20,
      show: true,
      feature: {
        saveAsImage: { show: false },
      }
    },
    legend: {
      orient: 'vertical',
      left: '65%',
      y: 'center',
      textStyle: {
        color: '#00baff'
      },
      data: nameArr
    },
    series: [
      {
        name: '',
        type: 'pie',
        center: ['32%', '50%'],
        radius: ['30%', '70%'],
        avoidLabelOverlap: false,
        label: {
          normal: {
            show: false,
            position: 'inner'
          },
          emphasis: {
            show: true,
            textStyle: {
              fontSize: '12'
            }
          }
        },
        labelLine: {
          normal: {
            show: false
          }
        },
        data: chartArr
      }
    ]
  }
  return option
}

// 获取比例图
export function getProOption (xAxis, values, colors) {
  var seriesData = []
  var titleData = []
  values.forEach(function (item, index) {
    titleData.push({
      text: '%' + '\n\n\n\n' + xAxis[index],
      left: ((70) / values.length) * (index + 1) - .5 + '%',
      top: '56%',
      textAlign: 'center',
      textStyle: {
        fontSize: '16',
        color: 'rgba(255,255,255,0.5)',
        fontWeight: '400',
      },
    })
    seriesData.push({
      type: 'pie',
      radius: ['55', '65'],
      center: [((70) / values.length) * (index + 1) + '%', '50%'],
      hoverAnimation: true,
      label: {
        normal: {
          position: 'center'
        },
      },
      data: [{
        value: item,
        itemStyle: {
          normal: {
            color: colors[index],
          }
        }
      },
        {
          value: 100 - item,
          name: '占位',
          tooltip: {
            show: true
          },
          itemStyle: {
            normal: {
              color: 'rgba(68, 163, 252, 1)',
            }
          },
          label: {
            normal: {
              formatter: item,
              textStyle: {
                fontSize: 36,
                color: 'rgba(255,255,255,1)',
              }
            },

          }
        }
      ]
    })
  })

  let option = {
    title: titleData,
    series: seriesData,
  }
  return option
}

//获取门诊急诊柱状图
export function getClinicBarOption (nameArr, xNameArr, chartArr) {
  let option = {

    tooltip: {
      trigger: 'axis'
    },
    legend: {
      top: '0',
      right: '200',
      textStyle: {
        color: '#00baff'
      },
      data: nameArr
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    toolbox: {
      padding: 20,
      right: 50,
      show: true,
      feature: {
        mark: { show: true },
        magicType: { show: true, type: ['line', 'bar'] },
        restore: { show: true },
        saveAsImage: { show: true },
      }
    },
    xAxis: {

      axisLabel: {
        textStyle: {
          color: '#00baff',//坐标值得具体的颜色
        }
      },
      data: xNameArr
    },
    yAxis: {
      type: 'value',
      nameTextStyle: {
        color: '#ebf8ac'
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: ['#315070'],
          width: 1,
          type: 'solid'
        }
      },
      axisLabel: {
        textStyle: {
          color: '#06c7bb',//坐标值得具体的颜色
        }
      }
    },
    series: []
  }

  chartArr.forEach(item => {
    item.type = 'bar'
    item.barWidth = 20
    item.stack = '总数'

    option.series.push(item)
  })

  return option
}

export function getRegisterBarOption (nameArr, xNameArr, chartArr) {
  let option = {

    tooltip: {
      trigger: 'axis'
    },
    legend: {
      top: '0',
      right: '200',
      textStyle: {
        color: '#00baff'
      },
      data: nameArr
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    toolbox: {
      padding: 20,
      right: 50,
      show: true,
      feature: {
        mark: { show: true },
        magicType: { show: true, type: ['line', 'bar'] },
        restore: { show: true },
        saveAsImage: { show: true },
      }
    },
    xAxis: {

      axisLabel: {
        textStyle: {
          color: '#00baff',//坐标值得具体的颜色
        }
      },
      data: xNameArr
    },
    yAxis: {
      type: 'value',
      nameTextStyle: {
        color: '#ebf8ac'
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: ['#315070'],
          width: 1,
          type: 'solid'
        }
      },
      axisLabel: {
        textStyle: {
          color: '#06c7bb',//坐标值得具体的颜色
        }
      }
    },
    series: []
  }

  chartArr.forEach(item => {
    item.type = 'bar'
    item.barWidth = 20
    item.stack = '总数'
    option.series.push(item)
  })

  return option
}
